import pickle
from typing import List, Dict, Tuple


def save_obj(obj, save_path):
    # 保存对象到文件
    with open(save_path, "wb") as f:
        pickle.dump(obj, f)


def load_obj(filename):
    # 从文件中加载对象
    with open(filename, "rb") as f:
        loaded_obj = pickle.load(f)
        return loaded_obj



def get_remain_data(total_text: set, valid_func, datas)->Tuple[List[str], Dict]:
    """_summary_

    Args:
        total_data (_type_): _description_
        valid_func (_type_): _description_
        datas List[Tuple[Str,Dict]]: 
    """
    valid_data = {}
    remain_text = set()
    valid_text = set()
    for data in datas:
        for text, label in data:
            if valid_func(label):
                valid_text.add(text)
                valid_data[text] = label
                
    remain_text = total_text - valid_text
    return remain_text, valid_data